/****** Object:  Stored Procedure [dbo].spChiTietPhieuNhapGet Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[BaoCaoCacKhachHangDaMuaSanPham]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[BaoCaoCacKhachHangDaMuaSanPham]
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		30/06/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[BaoCaoCacKhachHangDaMuaSanPham]
(
	@MaSanPham nvarchar(12),
	@TuNgay datetime,
	@DenNgay datetime
)
WITH ENCRYPTION
AS

SET NOCOUNT ON

SELECT * FROM tbl_Congty

SELECT 
	* 
FROM tbl_SanPham INNER JOIN tbl_DonViTinh ON [tbl_DonViTinh].MaDonVi= [tbl_SanPham].maDonVi 
WHERE Mathuoc = @MaSanPham


select
	tbl_KhachHang.*	
from
	tbl_KhachHang INNER JOIN tbl_PhieuXuat ON [tbl_KhachHang].MaKH = [tbl_PhieuXuat].MaKH
	INNER JOIN tbl_ChiTietPhieuXuat ON [tbl_PhieuXuat].SoPX = [tbl_ChiTietPhieuXuat].SoPX
	INNER JOIN tbl_LuuKho ON [tbl_ChiTietPhieuXuat].MaLuuKho=[tbl_LuuKho].MaLuuKho
	INNER JOIN tbl_SanPham ON [tbl_SanPham].MaThuoc = [tbl_LuuKho].MaThuoc
WHERE
	tbl_SanPham.MaThuoc = @MaSanPham
	And ((@TuNgay is null) or convert(date,@TuNgay)<=convert(date,tbl_PhieuXuat.NgayXuatkho))
	AND ((@DenNgay is null) or convert(date,@DenNgay)>=convert(date,tbl_PhieuXuat.NgayXuatkho))
GO
--GRANT EXECUTE ON [dbo].[spChiTietPhieuNhapGet] TO [sa]
--GO
